package com.example.monitoringsystem.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.monitoringsystem.bean.States;
import com.example.monitoringsystem.mapper.StatesMapper;
import com.example.monitoringsystem.service.StatesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class StatesServiceImpl implements StatesService {
    @Autowired
    private StatesMapper statesMapper;

    @Override
    public void changeHaveBeenRead(int patientId) {
        QueryWrapper<States> wrapper = new QueryWrapper<>();
        wrapper.eq("patient_id",patientId);
        States states = statesMapper.selectOne(wrapper);
        if (states.getHaveBeenRead() == 0){
            states.setHaveBeenRead(1);
        }
        else if(states.getHaveBeenRead() == 1){
            states.setHaveBeenRead(0);
        }
        statesMapper.update(states,wrapper);
    }

    @Override
    public void changeHaveBeenPrinted(int patientId) {
        QueryWrapper<States> wrapper = new QueryWrapper<>();
        wrapper.eq("patient_id",patientId);
        States states = statesMapper.selectOne(wrapper);
        if (states.getHaveBeenPrinted() == 0){
            states.setHaveBeenPrinted(1);
        }
        else if(states.getHaveBeenPrinted() == 1){
            states.setHaveBeenPrinted(0);
        }
        statesMapper.update(states,wrapper);
    }

    @Override
    public States findStatesById(int patientId) {
        QueryWrapper<States> wrapper = new QueryWrapper<>();
        wrapper.eq("patient_id",patientId);
        return statesMapper.selectOne(wrapper);
    }
}
